home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
rhstdlib.arc
/
STRCAT2L.ASM
< prev
next >
Wrap
Assembly Source File
|
1990-10-20
|
2KB
|
130 lines
stdlib segment para public 'slcode'
assume cs:stdlib
;
extrn sl_malloc:far
;
; strcat- Computes the lengths of two strings pointed at by es:di and follow-
; ing the call. It then allocates storage for a string long enough
; to hold the concatentation of these two strings. Finally, it con-
; catenates the two strings storing the resulting string into the new
; buffer. Returns ES:DI pointing at the new string.
;
; inputs:
;
; ES:DI- Points at the first string.
;
; Return address points at the string to append.
;
;
; outputs:
;
; ES:DI- Points at new string containing the concatenation of the
; two strings.
;
; carry=0 if no error.
; carry=1 if strcat2 could not allocate enough memory to hold
; the resulting string.
;
public sl_strcat2l
;
scptr1 dd ?
strlen1 dw ?
scptr2 equ 2[bp]
rtnadrs dw ?
strlen2 dw ?
;
sl_strcat2l proc far
push bp
mov bp, sp
push cx
push ax
push ds
push si
pushf
cld
;
; Save pointers to the strings
;
mov word ptr cs:scptr1, di
mov word ptr cs:scptr1+2, es
;
; Compute the length of the string following the call.
;
mov al, 0
les di, scptr2
mov cx, 0ffffh
repne scasb
mov cs:rtnadrs, di ;Save return address
neg cx
dec cx
mov cs:StrLen2, cx
;
; Find the end of the first string:
;
les di, cs:scptr1
mov cx, 0ffffh
repne scasb
neg cx
dec cx
dec cx
mov cs:StrLen1, cx
;
; Malloc the appropriate storage:
;
add cx, cs:StrLen2
call sl_malloc
jc BadStrCat2
;
; Save ptr to dest
;
push es
push di
;
; Copy the strings:
;
lds si, cs:scptr1
mov cx, cs:strlen1
shr cx, 1
jnc cs1
lodsb
stosb
cs1: rep movsw
lds si, scptr2
mov cx, cs:strlen2
shr cx, 1
jnc cs2
lodsb
stosb
cs2: rep movsw
;
mov ax, cs:rtnadrs
mov scptr2, ax
pop di
pop es
popf
pop si
pop ds
pop ax
pop cx
pop bp
clc
ret
;
BadStrCat2: mov es, word ptr cs:scptr1+2
mov si, word ptr cs:scptr1
mov ax, cs:rtnadrs
mov scptr2, ax
popf
pop di
pop ds
pop ax
pop cx
pop bp
stc
ret
sl_strcat2l endp
;
;
stdlib ends
end